package com.hly.musicbackground.model.music.rest;

import com.hly.musicbackground.Final.SongLinkFinal;
import com.hly.musicbackground.Utils.RequestContextUtils;
import com.hly.musicbackground.domain.SongLink;
import com.hly.musicbackground.model.music.VO.SongSheetListVO;
import com.hly.musicbackground.model.music.params.IDParams;
import com.hly.musicbackground.model.music.params.SongSheetEmitParams;
import com.hly.musicbackground.model.music.service.SongLinkService;
import com.hly.musicbackground.model.music.service.SongSheetService;
import com.hly.musicbackground.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 歌单
 * */
@RestController
@RequestMapping("/api/sheet")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "歌单")
public class SongSheetController {

    private final SongSheetService songSheetService;
    private final SongLinkService songLinkService;

    /**
     * 获取歌单列表
     * */
    @GetMapping("/list")
    @ApiOperation(value = "获取歌单列表")
    public Result<SongSheetListVO> list(){
        int userId = RequestContextUtils.getUser().getUserId();
        SongSheetListVO songSheetListVO = songSheetService.getSongSheetList(userId);
        return Result.ok(songSheetListVO);
    }

    /**
     * 新建修改歌单
     * */
    @PostMapping("/emit")
    @ApiOperation(value = "新建修改歌单")
    public Result emit(@RequestBody SongSheetEmitParams params){
        songSheetService.emitSongSheet(params, RequestContextUtils.getUser().getUserId());
        return Result.ok();
    }

    /**
     * 删除歌单
     * */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除歌单")
    public Result delete(@RequestBody IDParams params){
        songSheetService.delSongSheet(params.getId());
        return Result.ok();
    }
}
